package com.certification.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.certification.entity.Certification;
import com.certification.vo.CertificationVO;
import com.certification.vo.PageVO;
import com.certification.vo.ResponseMessage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @author copa
 * @createDate 2022-03-28 23:55
 * @function
 */
@Repository
public interface CertificationMapper extends BaseMapper<Certification> {

    @Select("SELECT cert_stage certStage, cert_status certStatus, school_invest_remark schoolInvestRemark " +
            "FROM certification  " +
            "WHERE principal_id = #{userId} AND id = #{certId} " +
            "ORDER BY id DESC  " +
            "LIMIT 1")
    Map<String, Object> selectCertResult(@Param("certId") Integer certId, @Param("userId") Integer userId);

    @Select("SELECT id, principal_id principalId, cert_level certLevel, create_time startTime, cert_stage certStage, cert_status certStatus, cert_profession_type certProfessionType " +
            "FROM certification  " +
            "WHERE principal_id = #{userId} AND cert_stage = #{certStage} " +
            "ORDER BY id DESC  ")
    IPage<CertificationVO> getCertByCertStageAndPrincipalIdPage(@Param("certStage") int certStage,
                                                                @Param("userId") Integer userId,
                                                                Page<CertificationVO> page);

    @Select("SELECT id  " +
            "FROM certification c  " +
            "WHERE c.principal_id = #{userId}   " +
            "ORDER BY id DESC  " +
            "LIMIT 1")
    String selectOneByUserId(@Param("userId") Long userId);
}
